<template>
    <div class="container">
        <div>
            <a href="https://wails.io" target="_blank">
                <img src="/wails.png" class="logo" alt="Wails logo" />
            </a>
            <a wml-openURL="https://developer.mozilla.org/en-US/docs/Web/JavaScript">
                <img src="/javascript.svg" class="logo vanilla" alt="JavaScript logo" />
            </a>
        </div>
        <h1>Wails + Javascript</h1>
        <div class="card">
            <div class="result" id="result">{{ rebdata ? rebdata : "Please enter your name below 👇" }}</div>
            <div class="input-box" id="input">
                <input class="input" id="name" type="text" autocomplete="off" />
                <button class="btn" @click="doGreet()">Greet</button>
                <!-- <button class="btn" @click="HandleOpenWindow()"><icon-export />打开新窗口</button> -->
            </div>
        </div>
        <div class="footer">
            <a-avatar :style="{ backgroundColor: '#14a9f8' }">GoFly</a-avatar>
            <div>
                <p>Go服务端向前端传实时数据</p>
            </div>
            <div>
                <p id="time">当前时间：{{ innerText ? innerText[0] : "Listening for Time event..." }}</p>
            </div>
        </div>
        <HelloWorld msg="Vite + Vue" />
    </div>
</template>
<script setup>
import { ref } from 'vue';
import HelloWorld from '@/components/HelloWorld.vue'
import { GreetService } from "../bindings/SchedulePlanning/service";
import { Events } from "@wailsio/runtime";
// import { Message } from '@arco-design/web-vue';
const rebdata = ref("")
const doGreet = () => {
    // Message.loading({ content: "获取中·请稍后", id: "greet", duration: 0 })
    let name = document.getElementById('name').value;
    if (!name) {
        name = 'anonymous';
    }
    GreetService.Greet(name).then((result) => {
        rebdata.value = result;
        // Message.success({ content: "获取成功", id: "greet", duration: 2000 })
    }).catch((err) => {
        // Message.error({ content: err, id: "greet", duration: 2000 })
        console.log("错误：", err);
    });
}
const innerText = ref("")
Events.On('time', (time) => {
    innerText.value = time.data;
});
//打开新窗口
const dbopenWin = ref(false)
const HandleOpenWindow = () => {
    // if (dbopenWin.value) return
    // // Message.loading({ content: "打开中·请稍后", id: "Open", duration: 0 })
    // dbopenWin.value = true
    // OpenWindow.Open("新窗口").then((result) => {
    //     setTimeout(() => {
    //         dbopenWin.value = false
    //         // Message.success({ content: result, id: "Open", duration: 2000 })
    //     }, 800)
    // }).catch((err) => {
    //     dbopenWin.value = false
    //     // Message.error({ content: err, id: "Open", duration: 2000 })
    //     console.log("错误：", err);
    // });
}

</script>
<style scoped>
.logo {
    height: 6em;
    padding: 1.5em;
    will-change: filter;
    transition: filter 300ms;
}

.logo:hover {
    filter: drop-shadow(0 0 2em #646cffaa);
}

.logo.vue:hover {
    filter: drop-shadow(0 0 2em #42b883aa);
}
</style>